#include "texttospeech.h"

#include <QStringList>
#include <QDebug>

/**
 * 由于Python C API和QProcess之间的python解释器之间的冲突，这段代
 * 码暂时弃用，即取消通过多线程来调用QProcess而是直接采取混合编程的方式。
 */




TextToSpeech::TextToSpeech(QObject *parent) : QObject(parent)
{
    m_process = new QProcess(this);
}

TextToSpeech::~TextToSpeech()
{
    m_process->close();
    delete m_process;
}

void TextToSpeech::speak(const QString &text)
{
    try {
        QString pythonPath = PYTHON;
        QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
        env.insert("PYTHONHOME", "/home/mhc/anaconda3/envs/modelscope");
        env.insert("LD_LIBRARY_PATH", "/home/mhc/anaconda3/envs/modelscope/lib");
        m_process->setProcessEnvironment(env);
        m_process->start(pythonPath, QStringList() << SCRIPT << text);
        m_process->waitForFinished();
        } catch (const QString& errorMsg) {
        qDebug() << errorMsg;
    }
}
